<?php
/**
 * @description: 公众号入口
 * @param {type} 
 * @return: 
 * @Author: 偻儸小卒[EdisonLiu_]
 * @Date: 2020-05-20 11:05:57
 */
namespace We7Test\Controller\Admin;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Database\Capsule\Manager as DB;

use We7Test\Models\Accapp\User;

class IndexController
{
	/**
	 *  使用laravel db操作
	 * @param ServerRequestInterface $request
	 * @param ResponseInterface $response
	 * @param array $args
	 * @return ResponseInterface
	 */
	public function index(ServerRequestInterface $request, ResponseInterface $response, array $args) {
		global $_W,$_GPC;
		/**
		 *  默认不知道 数据库前缀
		 */
		$user_table = tablename('account'); //
		$user_table = str_replace('`', '', $user_table); //hack

		$params = $request->getQueryParams();//查询query
		$result = DB::table($user_table)->limit(19)->get();//原生查询
		$users = User::query()->limit(10)->get(); // 对象方式
		$response = $response->withHeader('content-type', 'application/json');
		$response->getBody()->write(json_encode(['params'=>$params,'message'=>'欢迎来到管理后台！', 'db'=>$result, 'users'=>$users]));
		return $response;
	}


}